#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;

struct blocks
{
    int a, b, h;
    bool operator <(const blocks &x)const
    {
        if (a == x.a){
            return b < x.b;
        }
        else{
            return a < x.a;
        }
    }
}block[200];

int dp[200];

bool check(const blocks &x, const blocks &y)
{
    if (x.a < y.a&&x.b < y.b)
        return 1;
    return 0;
}

int main()
{
    int kase;
    int k = 1;
    while (cin >> kase&&kase != 0)
    {
        int x, y, z;
        int n = kase * 6;
        for (int i = 0; i < n;)
        {
            scanf("%d%d%d", &x, &y, &z);
            block[i].a = x, block[i].b = y, block[i].h = z, i++;
            block[i].a = x, block[i].b = z, block[i].h = y, i++;
            block[i].a = y, block[i].b = x, block[i].h = z, i++;
            block[i].a = y, block[i].b = z, block[i].h = x, i++;
            block[i].a = z, block[i].b = x, block[i].h = y, i++;
            block[i].a = z, block[i].b = y, block[i].h = x, i++;
        }
        sort(block, block + n);
        int Max = 0;
        for (int i = 0; i < n; i++)
        {
            dp[i] = block[i].h;
            for (int j = i - 1; j >= 0; j--)
            {
                if (check(block[j], block[i]) && dp[i] < dp[j] + block[i].h)
                    dp[i] = dp[j] + block[i].h;
            }
            if (Max < dp[i])
                Max = dp[i];

        }
        printf("Case %d: maximum height = %d\n", k++, Max);
    }
    
    return 0;
}
